package devicehandler

import (
	"github.com/gin-gonic/gin"
	"time"
	"yundian/internel/app/dao"
	"yundian/internel/app/models/devploys"
	"yundian/internel/app/models/devrule"
	"yundian/internel/pkg/dingo"
	. "yundian/internel/pkg/dingo/result"
)

// ------- 设备规则套餐相关API请求处理 deviceRuleHandler -------


// HandleInsertDeviceRule 新增设备规则API
func HandleInsertDeviceRule(ctx *gin.Context)  {
	m := devrule.New()
	dingo.ErrorIf(ctx.ShouldBindJSON(m))
	m.CreateAt = dingo.Time(time.Now().Unix()) // 设备类型创建时间

	Response(ctx)("", CodeSuccess, dao.NewDeviceRuleDao().InsertDevRule(m).Unwrap())(OK)
}

// HandleUpdateDeviceRule 修改设备规则 API
func HandleUpdateDeviceRule(ctx *gin.Context)  {
	m := devrule.New()
	dingo.ErrorIf(ctx.ShouldBindJSON(m))
	m.UpdateAt = dingo.Time(time.Now().Unix())

	Response(ctx)("", CodeSuccess, dao.NewDeviceRuleDao().UpdateDevRule(m).Unwrap())(OK)
}

func HandleInsertDeviceTypeDraw(ctx *gin.Context)  {
	m := devploys.New()
	dingo.ErrorIf(ctx.ShouldBindJSON(m))
	m.CreateAt = dingo.Time(time.Now().Unix()) // 设备类型创建时间

	Response(ctx)("", CodeSuccess, dao.NewDeviceRuleDao().InsertDevDraw(m).Unwrap())(OK)
}

func HandleUpdateDeviceTypeDraw(ctx *gin.Context)  {
	m := devploys.New()
	dingo.ErrorIf(ctx.ShouldBindJSON(m))
	m.UpdateAt = dingo.Time(time.Now().Unix())

	Response(ctx)("", CodeSuccess, dao.NewDeviceRuleDao().UpdateDevDraw(m).Unwrap())(OK)
}
